package com.ys.utils.kd;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Kd100Info {

    public String number;//订单号
    public String type;//快递公司
    public String typename;//快递公司名称
    public String logo;//快递公司logo
    public List<Map<String,Object>> list;//time 时间 status 状态，文字描述
    public int deliverystatus;//签收状态
    public String status;//签收状态名称

    public Kd100Info(JSONObject json){
        if (json != null) {

            this.number = json.getString("number");
            this.type = json.getString("type");
            this.typename = json.getString("typename");
            this.logo = json.getString("logo");
            this.deliverystatus = json.getInt("deliverystatus");
            this.list = new ArrayList<>();
            if (json.opt("list") != null) {
                JSONArray list = json.optJSONArray("list");
                for (int j = 0; j < list.size(); j++) {
                    JSONObject list_obj = (JSONObject) list.opt(j);
                    if (list_obj != null) {
                        Map<String,Object> map = new HashMap<>();
                        String time = list_obj.getString("time");
                        String status = list_obj.getString("status");
                        map.put("time",time);
                        map.put("status",status);
                        this.list.add(map);
                    }
                }
            }
            //物流状态
            if (json.getInt("deliverystatus") == 1) {
                this.status = "在途中";
            }
            if (json.getInt("deliverystatus") == 2) {
                this.status = "派件中";
            }
            if (json.getInt("deliverystatus") == 3) {
                this.status = "已签收";
            }
            if (json.getInt("deliverystatus") == 4)  {
                this.status = "派送失败(拒签等)";
            }
        }
    }
}
